import pygame

class StationFactory():
  def __init__(self):
    self.stationList = []
    self.numLeaks = 0
    self.numBreach = 0
    self.numEntity = 0

  def addHealthStation(self, pos, sprite, imagehandler, rectsize, stype, active):
    self.stationList.append(HealthStation(pos, sprite, imagehandler, rectsize, stype, active))

  def addLifeSupportStation(self,pos, sprite, imagehandler, rectsize, stype, active):
    self.stationList.append(LifeSupportStation(pos, sprite, imagehandler, rectsize, stype, active))

  def addAIStation(self,pos, sprite, imagehandler, rectsize, stype, active):
    self.stationList.append(AIStation(pos, sprite, imagehandler, rectsize, stype, active))

  def addNavigationStation(self,pos, sprite, imagehandler, rectsize, stype, active):
    self.stationList.append(NavigationStation(pos, sprite, imagehandler, rectsize, stype, active))

  def addPowerStation(self,pos, sprite, imagehandler, rectsize, stype, active):
    self.stationList.append(PowerStation(pos, sprite, imagehandler, rectsize, stype, active))

  def delEntity(self,item):
    self.stationList.remove(item)
    if item.type == "leak":
      self.numLeaks = self.numLeaks - 1
    if item.type == "breach":
      self.numBreach = self.numBreach - 1
    self.numEntity = self.numEntity - 1

  def addLeakEntity(self,pos, sprite, imagehandler, rectsize, stype, active):
    self.stationList.append(Entity(pos, sprite, imagehandler, rectsize, stype, active))
    self.numLeaks = self.numLeaks + 1
    self.numEntity = self.numEntity + 1

  def addAIPanelEntity(self,pos, sprite, imagehandler, rectsize, stype, active):
    self.stationList.append(Entity(pos, sprite, imagehandler, rectsize, stype, active))
    self.numEntity = self.numEntity + 1

  def addHealthEntity(self,pos, sprite, imagehandler, rectsize, stype, active):
    self.stationList.append(Entity(pos, sprite, imagehandler, rectsize, stype, active))
    self.numEntity = self.numEntity + 1

  def addBreachEntity(self,pos, sprite, imagehandler, rectsize, stype, active):
    self.stationList.append(Entity(pos, sprite, imagehandler, rectsize, stype, active))
    self.numBreach = self.numBreach + 1
    self.numEntity = self.numEntity + 1

  def draw(self,bgSurface):
    for station in self.stationList:
      if station.active == True:
        sprite = station.imagehandler.getSprite(station.sprite)
        pos = (station.pos[0] - (sprite.get_width() / 2), station.pos[1] - (sprite.get_height() / 2))
        bgSurface.blit(station.imagehandler.getSprite(station.sprite), pos)


class Station():
  def __init__ (self, isEvent, pos, sprite, imagehandler, rectsize, stype, active):
    self.isEvent = isEvent
    self.pos = pos
    self.sprite = sprite
    self.imagehandler = imagehandler
    self.rect = pygame.Rect(self.pos, rectsize)
    self.rect.center = self.pos
    self.type = stype
    self.active = active
    self.worked = 0
    self.working = False
    self.work_required = 100
    self.event = 0


  def draw (self, screen):
    if self.sprite != None and self.active != False:
      pos = (self.worldpos[0] - (sprite.get_width() / 2), self.worldpos[1] - (sprite.get_height() / 2))
      screen.blit(self.imagehandler.getSprite(self.sprite), self.pos)

class HealthStation(Station):
  def __init__(self,pos, sprite, imagehandler, rectsize, stype, active):
    Station.__init__(self,False, pos, sprite, imagehandler, rectsize, stype, active)


class LifeSupportStation(Station):
  def __init__(self,pos, sprite, imagehandler, rectsize, stype, active):
    Station.__init__(self, False, pos, sprite, imagehandler, rectsize, stype, active)


class AIStation(Station):
  def __init__(self,pos, sprite, imagehandler, rectsize, stype, active):
    Station.__init__(self, False, pos, sprite, imagehandler, rectsize, stype, active)


class NavigationStation(Station):
  def __init__(self,pos, sprite, imagehandler, rectsize, stype, active):
    Station.__init__(self, False, pos, sprite, imagehandler, rectsize, stype, active)


class PowerStation(Station):
  def __init__(self,pos, sprite, imagehandler, rectsize, stype, active):
    Station.__init__(self, False, pos, sprite, imagehandler, rectsize, stype, active)

class Entity(Station):
  def __init__(self,pos, sprite, imagehandler, rectsize, stype, active):
    Station.__init__(self, True, pos, sprite, imagehandler, rectsize, stype, active)


